package com.cn.zpark;

import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @PackageName: com.cn.zpark
 * @ClassName: ListToJson
 * @Description:将list集合转为json字符串
 * @author: RZS
 * @date: 2022/4/29  19:36
 */
public class ListToJson {
    public static void main(String[] args) {
        // 定义；list集合
        List<User> list = new ArrayList<>();
        list.add(new User(1, "张三", "123456"));
        list.add(new User(2, "大锤", "123456"));
        list.add(new User(3, "王二狗", "123456"));

        // 将list集合转为json字符串
        String jsonString = JSONObject.toJSONString(list);
        System.out.println(jsonString);
    }
}
